#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct milk {
    int x, y;
    milk(int _x, int _y) : x(_x), y(_y) {}
};
vector<milk> a;
bool compare(milk& a1, milk& a2) {
    return a1.x < a2.x;
}
int main() {
    int ans = 0;
    int m, n;
    cin >> m >> n;
    while(n--) {
        int x, y;
        cin >> x >> y;
        a.push_back(milk(x, y));
    }
    sort(a.begin(), a.end(), compare);
    for(int i = 0; i < a.size(); i++) {
        if(a[i].y <= m) {
            ans += a[i].x * a[i].y;
            m -= a[i].y;
        }else {
            ans += a[i].x * m;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}